<template>
	<view class="wrap">
		<u-form :model="dataForm" ref="uForm">
			<u-form-item label-position="left" label="入库数量:" prop="inQuantity" label-width="20%">
				<u-input type="number" :border="true" placeholder="请填写入库数量" v-model="dataForm.inQuantity" />
			</u-form-item>
			<u-form-item label-position="left" label="入库描述:" prop="inDescription" label-width="20%">
				<u-input type="textarea" :border="true" placeholder="请填写入库描述" v-model="dataForm.inDescription" />
			</u-form-item>
			<u-form-item label-position="left" label="入库图片:" prop="inImgUrl" label-width="20%">
				<u-upload width="160" height="160" :action="uploadUrl" :header="headers" :fileList="fileList"
					@on-success="success" @on-remove="uploadDelete" :deletable="true" max-count="1">
				</u-upload>
			</u-form-item>
		</u-form>
		<u-button @click="submit" type="primary">立即入库</u-button>
	</view>
	</view>
</template>

<script>
	import {
		submitInbound
	} from '@/api/product/product.js'
	export default {
		data() {
			return {
				uploadUrl: 'http://111.230.39.159:8181/police-security-system/piclocal/upload/pic',
				headers: {
					token: uni.getStorageSync('token')
				},
				fileList: [],
				dataForm: {
					productId: '',
					status: 0,
					inQuantity: '',
					inDescription: '',
					inImgUrl: ''
				},
				typeShow: false,
			}
		},
		onLoad(option) {
			this.fileList = []
			this.dataForm.productId = option.productId
		},
		methods: {
			success(data, index, lists, name) {
				console.log(data.data.imgAddress)
				this.dataForm.inImgUrl = data.data.imgAddress
			},
			// 图标删除回调函数
			uploadDelete(index, lists, name) {
				console.log(index)
				this.dataForm.inImgUrl = ''
			},
			submit() {
				console.log(this.dataForm)
				submitInbound(this.dataForm).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '入库申请成功！',
							icon: 'success'
						});
						uni.switchTab({
							url: '/pages/home/home'
						});
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						});
					}
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.agreement {
		display: flex;
		align-items: center;
		margin: 40rpx 0;

		.agreement-text {
			padding-left: 8rpx;
			color: $u-tips-color;
		}
	}
</style>